package com.jason.www.dao;

import com.jason.www.index.Movie;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;

/**
 * 继承ElasticsearchRepository<T, ID>，需要写两个泛型，第一个代表要存储的实体类型，第二个代表主键类型
 */
@Component
public interface MovieRepository extends ElasticsearchRepository<Movie,Long>{
    Movie queryMovieById(Long id);

    Page<Movie> findByTitleAndDirectorAndYearTimeStampOrYearTimeStampBetween(String title, String director, Long yearTimeStamp,Long yearTimeStampStart,Long yearTimeStampEnd, Pageable page);
}


/**
 *
 * 关键字	        使用示例	                            等同于的ES查询
 * And	            findByNameAndPrice	                    {“bool” : {“must” : [ {“field” : {“name” : “?”}}, {“field” : {“price” : “?”}} ]}}
 * Or	            findByNameOrPrice	                    {“bool” : {“should” : [ {“field” : {“name” : “?”}}, {“field” : {“price” : “?”}} ]}}
 * Is	            findByName	                            {“bool” : {“must” : {“field” : {“name” : “?”}}}}
 * Not	            findByNameNot	                        {“bool” : {“must_not” : {“field” : {“name” : “?”}}}}
 * Between	        findByPriceBetween	                    {“bool” : {“must” : {“range” : {“price” : {“from” : ?,”to” : ?,”include_lower” : true,”include_upper” : true}}}}}
 * LessThanEqual	findByPriceLessThan	                    {“bool” : {“must” : {“range” : {“price” : {“from” : null,”to” : ?,”include_lower” : true,”include_upper” : true}}}}}
 * GreaterThanEqual	findByPriceGreaterThan	                {“bool” : {“must” : {“range” : {“price” : {“from” : ?,”to” : null,”include_lower” : true,”include_upper” : true}}}}}
 * Before	        findByPriceBefore	                    {“bool” : {“must” : {“range” : {“price” : {“from” : null,”to” : ?,”include_lower” : true,”include_upper” : true}}}}}
 * After	        findByPriceAfter	                    {“bool” : {“must” : {“range” : {“price” : {“from” : ?,”to” : null,”include_lower” : true,”include_upper” : true}}}}}
 * Like	            findByNameLike	                        {“bool” : {“must” : {“field” : {“name” : {“query” : “? *”,”analyze_wildcard” : true}}}}}
 * StartingWith	    findByNameStartingWith	                {“bool” : {“must” : {“field” : {“name” : {“query” : “? *”,”analyze_wildcard” : true}}}}}
 * EndingWith	    findByNameEndingWith	                {“bool” : {“must” : {“field” : {“name” : {“query” : “*?”,”analyze_wildcard” : true}}}}}
 * Contains/Containing	findByNameContaining	            {“bool” : {“must” : {“field” : {“name” : {“query” : “?”,”analyze_wildcard” : true}}}}}
 * In	            findByNameIn(Collectionnames)	        {“bool” : {“must” : {“bool” : {“should” : [ {“field” : {“name” : “?”}}, {“field” : {“name” : “?”}} ]}}}}
 * NotIn	        findByNameNotIn(Collectionnames)	    {“bool” : {“must_not” : {“bool” : {“should” : {“field” : {“name” : “?”}}}}}}
 * True	            findByAvailableTrue	                    {“bool” : {“must” : {“field” : {“available” : true}}}}
 * False	        findByAvailableFalse	                {“bool” : {“must” : {“field” : {“available” : false}}}}
 * OrderBy	        findByAvailableTrueOrderByNameDesc	    {“sort” : [{ “name” : {“order” : “desc”} }],”bool” : {“must” : {“field” : {“available” : true}}}}
 *
 *
 * */